package main.java.indi.zyj.c150.dps;

import java.util.Scanner;

public class _02_SearchPerson {


    static int m, n;
    static boolean[][] visited = new boolean[110][110];
    static Character[][] map = new Character[110][110];


    public static boolean In(int x, int y){
        return x >= 0 && x < m && y >= 0 && y < n;
    }


    public static void Dfs(int x, int y){
        if (In(x, y) && !visited[x][y] && map[x][y] == '#'){
            visited[x][y] = true;
            Dfs(x-1, y);
            Dfs(x, y-1);
            Dfs(x+1, y);
            Dfs(x, y+1);
        }else {
            return;
        }

    }


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int person = 0;

        System.out.println("请输入迷宫的行列数:");
        m = scan.nextInt();
        n = scan.nextInt();

        for (int i = 0; i <m ; i++) {
            String s=scan.next();
            for (int j = 0; j <n ; j++) {
                map[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (map[i][j].equals('#') && !visited[i][j]){
                    Dfs(i, j);
                    person++;
                }
            }
        }
        System.out.println(person);

    }

}
